<h1>Récapitulatif des absences</h1>
<div id="dialogEditerSeances" title="Editer Séances">
    <form>
        <table class="liste scrollTable">
            <thead>
                <th  style="width: 30%;">Date</th><th  style="width: 20%;">Intitulé</th><th  style="width: 12%;">Matière</th><th  style="width: 20%;">Groupe TD</th><th  style="width: 18%;">Présence</th>
               
            </thead>
            <tbody id="tbodyEditerSeances">
               
            </tbody>
        </table> 
        <button class="right btn btn-default" type="button" id="buttonInputFormDialog" role="button" aria-disabled="false">Enregistrer</button>
    </form>
</div>
<div class="formFilter">
<form name="filtre" method="POST" action="index.php?controller=etudiant&action=index">
	<table>
        <tbody>      
		<tr>
                    <th>
                        <br><label for="name">Matière:</label>
                    </th>
                    <td>
                        <br><select name="matiere" id="fieldEp" >
                            <?php foreach ($listEP as $key => $ep) {
                                ?><option value='<?php echo $ep["numEP"] ?>' <?php echo ($ep["numEP"]==$formFilter->getNumEp()?"selected='selected'":"") ?> ><?php echo $ep["libelleEP"]?></option>
                            <?php }?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>    
                        <br><label for="annee">Annee d'enseignement:</label>
                    </th>
                    <td>
                        <br><select name="annee" id="fieldAnnee">
                            <?php for ($i = 2010; $i < (intval(date("Y"))+1); $i++) {?>
                            <option value="<?php echo $i;?>" <?php echo ($i==$formFilter->getAnnee()?"selected='selected'":"") ?> ><?php echo $i."-".($i+1);?></option>
                            <?php }?>
                        </select> 
                    </td>                
                </tr>
                <tr>
                    <th>
                        <br><label for="nom" id="fieldEtu">Nom de l'étudiant</label>
                    </th>
                    <td>
                        <br><input type="text" size="20" name="nom" style="cursor: text" value="<?php echo $formFilter->getNom(); ?>" /><br />
                    </td>
		</tr>
                
                
		<tr>
                    <th>    
                        <br><label for="numGroupe">Numéro groupe:</label>
                    </th>
                    <td>
                        <br><select name="numGroupe" id="fieldNumGroupe">
                            <option value=""></option>
                            <?php for ($i = 1; $i < 7; $i++) {?>
                            <option value="<?php echo $i;?>" <?php echo ($i==$formFilter->getGroupe()?"selected='selected'":"") ?> ><?php echo $i;?></option>
                            <?php }?>
                         </select>
                    </td>                
                </tr>
        </tbody>      
        <tfoot>
            <tr>
                    <td colspan="2"> 
                         <input value="Valider" type="submit" class="right btn btn-default">
                         <button type="reset" class="right btn btn-default">Annuler</button>
                    </td>
            </tr>  
        </tfoot>        
        </table>
       
</form>
</div>
<div class="resultats" id="listeEtudiants">
<?php include("view/listeEtudiants.php");?>
</div>
<script language="javascript">
$( document ).ready((function() {
    $("#fieldEp").change(function () {
        $( "#fieldGroupe" ).load( "index.php?controller=seance&action=ajaxGetGroupes&numEp="+$("#fieldEp").val());
    });
     $( "#dialogEditerSeances" ).dialog({
        autoOpen: false,
        width: 600,
        show: {
        effect: "blind",
        duration: 1000
        },
        hide: {
        effect: "explode",
        duration: 1000
        }
        
    });
    $(".editerEtu").click(function () {
        var numEtu=$(this).attr("id").substring(10);
        var nomEtu=$("#editerEtuN_"+numEtu).text();
        var prenomEtu=$("#editerEtuP_"+numEtu).text();
        
        
        $("#ui-id-1").text("Séances de "+prenomEtu+" "+nomEtu);
        $.ajax({
            url: "index.php?controller=etudiant&action=ajaxGetSeances&numEp="+$("#fieldEp").val()+"&numEtu="+numEtu+"&annee="+$("#fieldAnnee").val()+"&numgrp="+$("#fieldNumGroupe").val(),
            context: document.body
        }).done(function(data) {
            $('#tbodyEditerSeances').html(data);
            $( "#dialogEditerSeances" ).dialog("open");
        });
    });
        $("#buttonInputFormDialog").click(function () {

        var idSeances= new Array();
        var presences= new Array();
        var numEtudiant;

        var i=0;
        var j=0;
        var k=0;

        $.each( $(".fieldPresence"), function() {
            presences[i]=$(this).val();
        i++;
        });
               
        
        $.each( $(".fieldIdSeance"), function() {
            idSeances[j]=$(this).val();
            j++;
        });
        numEtudiant=$("#fieldNumEtudiant").val();
        var numgroupe=$("#fieldNumGroupe").val();
        var anneeSco=$("#fieldAnnee").val();
        var ep=$("#fieldEp").val();
        $.ajax({
            type: "POST",
            url: "index.php?controller=etudiant&action=ajaxUpdateSeances",
            data: { numEtu: numEtudiant, pres: presences, ids: idSeances, numgrp: numgroupe, annee: anneeSco, numEP: ep}
        })
        .done(function( data ) {
                $( "#dialogEditerSeances" ).dialog("close");
                location.reload();
            }).fail(function(data) {
                alert( data );
            });
    });
}));
</script>